#!/usr/bin/env bash

# ---
# IMPORTANT: Use the following statement at the TOP OF EVERY TEST SCRIPT
#            to ensure that this package's 'bin/' subfolder is added to the path so that
#            this package's CLIs can be invoked by their mere filename in the rest
#            of the script.
# ---
PATH=${PWD%%/test*}/bin:$PATH

# Helper function for error reporting.
die() { (( $# > 0 )) && echo "ERROR: $*" >&2; exit 1; }

# Derive distinct set of languages from `say -v \?` output.
allLangsRef=$(say -v \? | grep -Eo " [a-z]{2}[_-]\w+ " | tr -d ' ' | sort -u)

# Do the same with `voices -L -a`.
allLangs=$(voices -L -a)

# Ensure the two match.
[[ "$allLangs" == "$allLangsRef" ]] || die "Lists of installed languages didn't match: "$'\n'"$(diff <(echo "$allLangs") <(echo "$allLangsRef"))"

exit 0
